package com.github.hxl.upload.demo.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.github.hxl.upload.demo.config.Config;
import com.github.hxl.upload.demo.util.FileUploadUtil;

/**
 * @author: shizi
 */
public class FileUploadServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		try {
			FileUploadUtil.upload(request, Config.fileDir, null);

			request.setAttribute("message", "上传成功");
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("message", "上传失败");
		}
		request.getRequestDispatcher("/jsp/upload.jsp").forward(request, response);
	}
}
